]> git.r.bdr.sh - rbdr/map/blobdiff - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
Map 3 first commit: files, groups and layout
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
index b12dabce12393e4de8752055b4939b0adbaac0f4..b256861f6ed8e36eb0a1c30ae8f89bbb5c81c90f 100644 (file)
@@ -5,20 +5,24 @@ import SwiftUI
 
 struct MapRenderView: View {
 
-  @Binding var content: String
+  @Binding var document: MapDocument
   @Binding var evolution: StageType
-  
+
   var stage: Stage {
     Stage.stages(evolution)
   }
 
-  @State var parsedMap: ParsedMap = ParsedMap.empty
+  var parsedMap: ParsedMap {
+    MapParser.parse(content: document.text)
+  }
 
-  let mapSize = CGSize(width: 1300.0, height: 1000.0)
+  let mapSize = Dimensions.mapSize
+  let padding = Dimensions.mapPadding
 
   let lineWidth = CGFloat(0.5)
   let vertexSize = CGSize(width: 25.0, height: 25.0)
-  let padding = CGFloat(30.0)
+
+  var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
 
   var body: some View {
     ZStack(alignment: .topLeading) {
@@ -36,28 +40,27 @@ struct MapRenderView: View {
       MapEdges(
         mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
       MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
-      MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices)
+      MapVertices(
+        mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
+        onDragVertex: onDragVertex)
       MapOpportunities(
         mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
         opportunities: parsedMap.opportunities)
+      MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
+        opaque: true
+      ).opacity(0.1)
       MapNotes(
         mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
-    }.frame(
-      width: mapSize.width,
+    }.offset(x: padding, y: padding).frame(
+      width: mapSize.width + 2 * padding,
       height: mapSize.height + 2 * padding, alignment: .topLeading
-    ).onAppear {
-      self.parsedMap = Map.parse(content: content)
-    }.padding(padding).onChange(of: content) { newState in
-      self.parsedMap = Map.parse(content: newState)
-    }
+    )
   }
 }
 
-struct MapRenderView_Previews: PreviewProvider {
-  static var previews: some View {
-    MapRenderView(
-      content: Binding.constant(""), evolution: Binding.constant(StageType.general)
-    ).environment(
-      \.managedObjectContext, PersistenceController.preview.container.viewContext)
-  }
+#Preview {
+  MapRenderView(
+    document: Binding.constant(MapDocument(text: "")),
+    evolution: Binding.constant(StageType.general)
+  )
 }